package com.zhiyou.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.zhiyou.mapper.Fy_qsen;
import com.zhiyou.model.Fy_Qsen;
import com.zhiyou.model.ShareImg;
import com.zhiyou.service.Fy_QsenService;
import com.zhiyou.utils.FTPUtil;
@Service
public class Fy_QsenServiceImpl implements Fy_QsenService{
@Autowired
Fy_qsen fy_qsen;
	@Override
	public void addFy_Qsen(Fy_Qsen fy_Qsen,MultipartFile[] files) {
		if (files != null) {
			for (MultipartFile multipartFile : files) {
				String image=FTPUtil.setImage(multipartFile);
				Fy_Qsen fyQsen=fy_Qsen;
				fyQsen.setQsen_url_text(image);
				fy_qsen.addFy_Qsen_Url(fyQsen);
			}
		}
		fy_qsen.addFy_Qsen(fy_Qsen);
	}
	@Override
	public void updateFy_Qsen(Fy_Qsen fy_Qsen,MultipartFile[] files) {
		List<Fy_Qsen> fyQsen=fy_qsen.selectFy_QsenByID(fy_Qsen.getQsen_id());
		for (Fy_Qsen fy_Qsen2 : fyQsen) {
			if (fy_Qsen2!=null) {
				System.out.println(fy_Qsen2.getQsen_url_text());
				FTPUtil.rmImage(fy_Qsen2.getQsen_url_text());
			}
		}
		if (files != null) {
			for (MultipartFile multipartFile : files) {
				String image=FTPUtil.setImage(multipartFile);
				Fy_Qsen fyQsen3=fy_Qsen;
				fyQsen3.setQsen_url_text(image);
				fy_qsen.updateFy_Qsen_Url(fyQsen3);
			}
		}
		fy_qsen.updateFy_Qsen(fy_Qsen);
	}
	@Override
	public void deleteFy_Qsen(Integer qsen_id) {
		Fy_Qsen selectFy_QsenByID1 = fy_qsen.selectFy_QsenByID1(qsen_id);
		System.out.println(selectFy_QsenByID1);		
		//删除图片
		List<Fy_Qsen> fyQsen=fy_qsen.selectFy_QsenByID(qsen_id);
		for (Fy_Qsen fy_Qsen2 : fyQsen) {
			FTPUtil.rmImage(fy_Qsen2.getQsen_url_text());
		}
		fy_qsen.deleteFy_Qsen_Url(selectFy_QsenByID1.getQsen_url_type());
		fy_qsen.deleteFy_Qsen(qsen_id);
	}
	@Override
	public List<Fy_Qsen> selectAllFy_Qsen(Integer qsen_type) {
		return fy_qsen.selectAllFy_Qsen(qsen_type);
	}

	@Override
	public List<Fy_Qsen> selectFy_QsenByID(Integer qsen_id) {
		Fy_Qsen fq=fy_qsen.selectFy_QsenByID1(qsen_id);
		fq.setQsen_read(fq.getQsen_read()+1);
		fy_qsen.updateFy_Qsen(fq);
		System.out.println(fq);
		return fy_qsen.selectFy_QsenByID(qsen_id);
	}

	@Override
	public List<Fy_Qsen> selectFy_Qsen() {
		return fy_qsen.selectFy_Qsen();
	}

}
